package com.example.chapter05;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class AlertDialogActivity extends AppCompatActivity implements View.OnClickListener {

    private TextView tv_alert;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_alert_dialog);
        findViewById(R.id.btn_alert).setOnClickListener(this);
        tv_alert = findViewById(R.id.tv_alert);
    }

    @Override
    public void onClick(View v) {
        // 创建提醒对话框的构造器
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        // 设置对话框的标题
        builder.setTitle("尊敬的用户");
        // 设置对话框的内容
        builder.setMessage("你真的要卸载我吗？");
        builder.setPositiveButton("残忍卸载", (dialog, which) -> {
            tv_alert.setText("残忍卸载成功");
        });
         builder.setNegativeButton("我再想想", (dialog, which) -> {
            tv_alert.setText("放弃卸载");
        });
        // 创建构建器串接提醒对话框对象
        AlertDialog dialog = builder.create();
        dialog.show();
    }
}